﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Remember.WPF.Views
{
    /// <summary>
    /// Interaction logic for BookItemControl.xaml
    /// </summary>
    public partial class BookItemControl : UserControl
    {
        public string catID;
        public event EventHandler OnClickTitle;
        public event EventHandler OnClickEdit;
        public event EventHandler OnCheckStatus;
        public BookItemControl()
        {
            InitializeComponent();
            this.checkBoxStatus.Click += new RoutedEventHandler(checkBoxStatus_Click);
            
        }

        void checkBoxStatus_Click(object sender, RoutedEventArgs e)
        {
            if (checkBoxStatus.IsChecked != null && checkBoxStatus.IsChecked.Value)
            {
                if (OnCheckStatus != null)
                {
                    OnCheckStatus(sender, e);
                }
            }
            else
            { 
            }
        }

        private void uiBookName_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {

        }

        private void uiBookName_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            this.uiBorder.Background = new SolidColorBrush(Colors.LimeGreen);

            if (sender != null)
            {
                string bookID = (sender as TextBlock).Tag.ToString ();
                if (OnClickTitle != null)
                {
                    OnClickTitle(bookID, null);
                }
            }
        }

        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            if (sender != null)
            {
                string bookID = (sender as Button).Tag.ToString ()  ;
                if (OnClickEdit != null)
                {
                    OnClickEdit(bookID, null);
                }
            }
        }

        Brush borderBrush = null;

        private void UserControl_MouseEnter(object sender, MouseEventArgs e)
        {
            borderBrush = this.uiBorder.BorderBrush;
            this.uiBorder.BorderBrush = new SolidColorBrush(Colors.LimeGreen);

            uiBookName.TextDecorations = TextDecorations.Underline;

        }

        private void UserControl_MouseLeave(object sender, MouseEventArgs e)
        {
            uiBookName.TextDecorations = null;
            if (borderBrush != null)
            {
                this.uiBorder.BorderBrush = borderBrush as SolidColorBrush;
            }

        }
    }
}
